/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.excesys.exsecs.om.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.excel.annotation.ResponseExcel;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.om.dto.EquipmentModelDto;
import com.excesys.exsecs.om.entity.OmEquipmentModelMaintenance;
import com.excesys.exsecs.om.entity.OmMaintenanceItems;
import com.excesys.exsecs.om.service.OmEquipmentModelService;
import com.excesys.exsecs.om.service.OmMaintenanceService;
import com.excesys.exsecs.om.vo.EquipmentModelExcelVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 保养模板
 *
 * @author
 * @date 2023-08-01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/omequipmentmodel"  )
@Tag(name = "保养模板")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OmEquipmentModelController {
	private final OmEquipmentModelService omEquipmentModelService;

	private final OmMaintenanceService omMaintenanceService;
	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param equipmentModelMaintenance 保养模板
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page" )
	//@PreAuthorize("@pms.hasPermission('om_omequipmentmodel_get')" )
	public R getOmICheckRoutePage(Page page, OmEquipmentModelMaintenance equipmentModelMaintenance) {
		return R.ok(omEquipmentModelService.getOmEquipMentModel(page,equipmentModelMaintenance));
	}

	/**
	 * 新增保养模板
	 * @param equipmentModelDto 新增保养模板
	 * @return R
	 */
	@Operation(summary = "新增保养模板", description = "新增保养模板")
	@SysLog("新增保养模板" )
	@PostMapping
	//@PreAuthorize("@pms.hasPermission('om_omequipmentmodel_add')" )
	public R save(@RequestBody EquipmentModelDto equipmentModelDto) {
		return R.ok(omEquipmentModelService.saveOmEquimentModel(equipmentModelDto));
	}

	/**
	 * 通过id删除维修模板
	 * @param exId id
	 * @return R
	 */
	@Operation(summary = "通过id删除维修模板", description = "通过id删除维修模板")
	@SysLog("通过id删除维修模板" )
	@DeleteMapping("/{exId}" )
	//@PreAuthorize("@pms.hasPermission('om_omrepairmodel_del')" )
	public R removeById(@PathVariable Integer exId) {
		return R.ok(omEquipmentModelService.removeById(exId));
	}

	/**
	 * 修改维修模板
	 * @param equipmentModelMaintenance 修改维修模板
	 * @return R
	 */
	@Operation(summary = "修改维修模板", description = "修改维修模板")
	@SysLog("修改维修模板" )
	@PutMapping
	//@PreAuthorize("@pms.hasPermission('om_omrepairmodel_edit')" )
	public R updateById(@RequestBody OmEquipmentModelMaintenance equipmentModelMaintenance) {
		return R.ok(omEquipmentModelService.updateById(equipmentModelMaintenance));
	}

	/**
	 * 删除多个设备维修模板
	 *
	 * @param idList 删除多个设备维修模板
	 * @return R
	 */
	@Operation(summary = "删除多个设备维修模板", description = "删除多个设备维修模板")
	@SysLog("删除多个设备维修模板")
	@DeleteMapping("/removeByIds")
	//@PreAuthorize("@pms.hasPermission('om_omicheckpoint_del')")
	public R removeByIds(@RequestBody List<Integer> idList) {
		for(int i=0;i<idList.size();i++){
			omMaintenanceService.deleteById(idList.get(i).toString());
		}
		return R.ok(omEquipmentModelService.removeByIds(idList));
	}

	/**
	 * 修改维修模板
	 * @param omMaintenanceItems 修改维修模板
	 * @return R
	 */
	@Operation(summary = "修改维修模板", description = "修改维修模板")
	@SysLog("修改保养项目内容" )
	@PutMapping("/editItems")
	//@PreAuthorize("@pms.hasPermission('om_omrepairmodel_edit')" )
	public R updateItemsById(@RequestBody OmMaintenanceItems omMaintenanceItems) {
		return R.ok(omMaintenanceService.updateById(omMaintenanceItems));
	}

	/**
	 * 通过id删除维修模板
	 * @param exId id
	 * @return R
	 */
	@Operation(summary = "通过id删除维修模板", description = "通过id删除维修模板")
	@SysLog("通过id删除维修模板" )
	@DeleteMapping("/deleteById/{exId}" )
	//@PreAuthorize("@pms.hasPermission('om_omrepairmodel_del')" )
	public R deleteById(@PathVariable Integer exId) {
		return R.ok(omMaintenanceService.remove(exId));
	}


	/**
	 * 新增保养模板
	 * @param omMaintenanceItems 新增保养模板
	 * @return R
	 */
	@Operation(summary = "新增保养模板", description = "新增保养模板")
	@SysLog("新增保养模板" )
	@PostMapping("/saveItems")
	//@PreAuthorize("@pms.hasPermission('om_omequipmentmodel_add')" )
	public R saveItems(@RequestBody OmMaintenanceItems omMaintenanceItems) {
		return R.ok(omMaintenanceService.save(omMaintenanceItems));
	}


	/**
	 * 导出excel 表格
	 * @return
	 */

	@Operation(summary = "导出所有数据", description = "导出所有数据")
	@ResponseExcel
	@GetMapping("/export")
	//@PreAuthorize("@pms.hasPermission('om_omrepairmodel_export')")
	public List<EquipmentModelExcelVo> export() {
		return omEquipmentModelService.listBamSBuildings();
	}


	/**
	 * 根据设备编码查询模板
	 * @return
	 */

	@Operation(summary = "根据设备编码查询模板", description = "根据设备编码查询模板")
	@GetMapping("/getListByModelCode/{modelCode}")
	//@PreAuthorize("@pms.hasPermission('om_omrepairmodel_export')")
	public List<OmEquipmentModelMaintenance> getListByModelCode(@PathVariable("modelCode") String modelCode) {
		return omEquipmentModelService.getListByModelCode(modelCode);
	}
}
